#pragma once

#include "Entity.h"
#include "Vector.h"
#include "UnitDerive.h"
#include "BoundBox.h"
#include "DrawCellManager.h"

namespace mini
{
	class CActor : public CEntity
	{
		friend class CRenderNode;
		friend class CScene;
		friend class CRenderViewport;
	public:
		CActor();
		virtual ~CActor();
		bool operator==(CActor& actor);
		virtual bool initialise(const std::string& fileName, const std::string& materilaName, ResType type = Mesh);
		virtual bool initialise(const std::string& fileName, ResType type);
		virtual bool loadAnimation(const std::string& fileName);
		virtual bool initialiseMaterial(const std::string& szfile);
		virtual void updateUnitProperty(Property* pProperty);
		virtual std::pair<bool, float> isPick(const CVector& v, bool isPickBound = true);
		virtual std::pair<bool, float> isPick(const CVector& origin, const CVector& dir, bool isPickBound = true);
		
		virtual void setPosition(CVector pt, bool bUpdate = false);
		virtual void setScale(CVector scale, bool bUpdate = false);
		virtual void setRotation(CVector rotation, bool bUpdate = false);
		void bindMeshUnit( CMeshUnit* pMeshUnit );
		void removeMeshUnit(CMeshUnit* pMeshUnit);
		void removeAllMeshUnit();
		void hideAllMeshUnit();
		std::list<CMeshUnit*>& getMeshUnits();
		std::list<CMaterialUnit*>& getMaterials();

		CVector& getPosition();
		CVector& getScale();
		CVector& getRotation();
		CBoundBox&	getBoundBox();
		void showBoundBox();
		void hideBoundBox();
		void setBoundBoxShow( bool bValue);
		bool isAllowPick();
		void disablePick();
		void activePick();
		bool isAlwayShow();

	private:
		void updateMeshUnitMatrix(float fDeltaTime);
		void ClearMeshUnits();

	protected:
		virtual void update(float fDeltaTime);
		virtual void updateFrame(float fDeltaTime) override;
		virtual void initialiseFinished();

	protected:
		CSkeleton* mpSkeleton = nullptr;
		CModel* mpModel = nullptr;
		CBoundBox				mBoundBox;
		CVector					mPosition;
		CVector					mScale;
		CVector					mRotation;

		std::list<CMeshUnit*>		mpMeshUnits;
		std::list<CMaterialUnit*>	mpMaterialUnits;
		std::list<DrawCell*>		mDrawCells;
		
		bool					mbPick = true;
		bool					mbAlwayShow = false;
	};
}



